home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 May / maximum-cd-2009-05.iso / DiscContents / Firefox Setup 3.0.6.exe / nonlocalized / chrome / toolkit.jar / content / global / charsetOverlay.js < prev    next >
Encoding:
Text File  |  2008-07-23  |  8.4 KB  |  273 lines

  1. function MultiplexHandler(event)
  2. {
  3.     var node = event.target;
  4.     var name = node.getAttribute('name');
  5.  
  6.     if (name == 'detectorGroup') {
  7.         SetForcedDetector(true);
  8.         SelectDetector(event, false);
  9.     } else if (name == 'charsetGroup') {
  10.         var charset = node.getAttribute('id');
  11.         charset = charset.substring('charset.'.length, charset.length)
  12.         SetForcedCharset(charset);
  13.     } else if (name == 'charsetCustomize') {
  14.         //do nothing - please remove this else statement, once the charset prefs moves to the pref window
  15.     } else {
  16.         SetForcedCharset(node.getAttribute('id'));
  17.     }
  18. }
  19.  
  20. function MailMultiplexHandler(event)
  21. {
  22.     var node = event.target;
  23.     var name = node.getAttribute('name');
  24.  
  25.     if (name == 'detectorGroup') {
  26.         SelectDetector(event, true);
  27.     } else if (name == 'charsetGroup') {
  28.         var charset = node.getAttribute('id');
  29.         charset = charset.substring('charset.'.length, charset.length)
  30.         MessengerSetForcedCharacterSet(charset);
  31.     } else if (name == 'charsetCustomize') {
  32.         //do nothing - please remove this else statement, once the charset prefs moves to the pref window
  33.     } else {
  34.         MessengerSetForcedCharacterSet(node.getAttribute('id'));
  35.     }
  36. }
  37.  
  38. function ComposerMultiplexHandler(event)
  39. {
  40.     var node = event.target;
  41.     var name = node.getAttribute('name');
  42.  
  43.     if (name == 'detectorGroup') {
  44.         ComposerSelectDetector(event, true);
  45.     } else if (name == 'charsetGroup') {
  46.         var charset = node.getAttribute('id');
  47.         charset = charset.substring('charset.'.length, charset.length)
  48.         EditorSetDocumentCharacterSet(charset);
  49.     } else if (name == 'charsetCustomize') {
  50.         //do nothing - please remove this else statement, once the charset prefs moves to the pref window
  51.     } else {
  52.         SetForcedEditorCharset(node.getAttribute('id'));
  53.     }
  54. }
  55.  
  56. function SelectDetector(event, doReload)
  57. {
  58.     dump("Charset Detector menu item pressed: " + event.target.getAttribute('id') + "\n");
  59.  
  60.     var uri =  event.target.getAttribute("id");
  61.     var prefvalue = uri.substring('chardet.'.length, uri.length);
  62.     if ("off" == prefvalue) { // "off" is special value to turn off the detectors
  63.         prefvalue = "";
  64.     }
  65.  
  66.     try {
  67.         var pref = Components.classes["@mozilla.org/preferences-service;1"]
  68.                              .getService(Components.interfaces.nsIPrefBranch);
  69.         var str =  Components.classes["@mozilla.org/supports-string;1"]
  70.                              .createInstance(Components.interfaces.nsISupportsString);
  71.  
  72.         str.data = prefvalue;
  73.         pref.setComplexValue("intl.charset.detector",
  74.                              Components.interfaces.nsISupportsString, str);
  75.         if (doReload) window.content.location.reload();
  76.     }
  77.     catch (ex) {
  78.         dump("Failed to set the intl.charset.detector preference.\n");
  79.     }
  80. }
  81.  
  82. function ComposerSelectDetector(event)
  83. {
  84.     //dump("Charset Detector menu item pressed: " + event.target.getAttribute('id') + "\n");
  85.  
  86.     var uri =  event.target.getAttribute("id");
  87.     var prefvalue = uri.substring('chardet.'.length, uri.length);
  88.     if ("off" == prefvalue) { // "off" is special value to turn off the detectors
  89.         prefvalue = "";
  90.     }
  91.  
  92.     try {
  93.         var pref = Components.classes["@mozilla.org/preferences-service;1"]
  94.                              .getService(Components.interfaces.nsIPrefBranch);
  95.         var str =  Components.classes["@mozilla.org/supports-string;1"]
  96.                              .createInstance(Components.interfaces.nsISupportsString);
  97.  
  98.         str.data = prefvalue;
  99.         pref.setComplexValue("intl.charset.detector",
  100.                              Components.interfaces.nsISupportsString, str);
  101.         EditorLoadUrl(GetDocumentUrl());    
  102.     }
  103.     catch (ex) {
  104.         dump("Failed to set the intl.charset.detector preference.\n");
  105.     }
  106. }
  107.  
  108. function SetForcedDetector(doReload)
  109. {
  110.     BrowserSetForcedDetector(doReload);
  111. }
  112.  
  113. function SetForcedCharset(charset)
  114. {
  115.     BrowserSetForcedCharacterSet(charset);
  116. }
  117.  
  118. var gPrevCharset = null;
  119. function UpdateCurrentCharset()
  120. {
  121.     // extract the charset from DOM
  122.     var wnd = document.commandDispatcher.focusedWindow;
  123.     if ((window == wnd) || (wnd == null)) wnd = window.content;
  124.  
  125.     // Uncheck previous item
  126.     if (gPrevCharset) {
  127.         var pref_item = document.getElementById('charset.' + gPrevCharset);
  128.         if (pref_item)
  129.           pref_item.setAttribute('checked', 'false');
  130.     }
  131.  
  132.     var menuitem = document.getElementById('charset.' + wnd.document.characterSet);
  133.     if (menuitem) {
  134.         menuitem.setAttribute('checked', 'true');
  135.     }
  136. }
  137.  
  138. function UpdateCurrentMailCharset()
  139. {
  140.     var charset = msgWindow.mailCharacterSet;
  141.     var menuitem = document.getElementById('charset.' + charset);
  142.  
  143.     if (menuitem) {
  144.         menuitem.setAttribute('checked', 'true');
  145.     }
  146. }
  147.  
  148. function UpdateCharsetDetector()
  149. {
  150.     var prefvalue;
  151.  
  152.     try {
  153.         var pref = Components.classes["@mozilla.org/preferences-service;1"]
  154.                              .getService(Components.interfaces.nsIPrefBranch);
  155.         prefvalue = pref.getComplexValue("intl.charset.detector",
  156.                                          Components.interfaces.nsIPrefLocalizedString).data;
  157.     }
  158.     catch (ex) {
  159.         prefvalue = "";
  160.     }
  161.  
  162.     if (prefvalue == "") prefvalue = "off";
  163.     dump("intl.charset.detector = "+ prefvalue + "\n");
  164.  
  165.     prefvalue = 'chardet.' + prefvalue;
  166.     var menuitem = document.getElementById(prefvalue);
  167.  
  168.     if (menuitem) {
  169.         menuitem.setAttribute('checked', 'true');
  170.     }
  171. }
  172.  
  173. function UpdateMenus(event)
  174. {
  175.     // use setTimeout workaround to delay checkmark the menu
  176.     // when onmenucomplete is ready then use it instead of oncreate
  177.     // see bug 78290 for the detail
  178.     UpdateCurrentCharset();
  179.     setTimeout(UpdateCurrentCharset, 0);
  180.     UpdateCharsetDetector();
  181.     setTimeout(UpdateCharsetDetector, 0);
  182. }
  183.  
  184. function CreateMenu(node)
  185. {
  186.   var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
  187.   observerService.notifyObservers(null, "charsetmenu-selected", node);
  188. }
  189.  
  190. function UpdateMailMenus(event)
  191. {
  192.     // use setTimeout workaround to delay checkmark the menu
  193.     // when onmenucomplete is ready then use it instead of oncreate
  194.     // see bug 78290 for the detail
  195.     UpdateCurrentMailCharset();
  196.     setTimeout(UpdateCurrentMailCharset, 0);
  197.     UpdateCharsetDetector();
  198.     setTimeout(UpdateCharsetDetector, 0);
  199. }
  200.  
  201. var gCharsetMenu = Components.classes['@mozilla.org/rdf/datasource;1?name=charset-menu'].getService().QueryInterface(Components.interfaces.nsICurrentCharsetListener);
  202. var gLastBrowserCharset = null;
  203.  
  204. function charsetLoadListener (event)
  205. {
  206.     var charset = window.content.document.characterSet;
  207.  
  208.     if (charset.length > 0 && (charset != gLastBrowserCharset)) {
  209.         gCharsetMenu.SetCurrentCharset(charset);
  210.         gPrevCharset = gLastBrowserCharset;
  211.         gLastBrowserCharset = charset;
  212.     }
  213. }
  214.  
  215.  
  216. function composercharsetLoadListener (event)
  217. {
  218.     var charset = window.content.document.characterSet;
  219.  
  220.  
  221.     if (charset.length > 0 ) {
  222.        gCharsetMenu.SetCurrentComposerCharset(charset);
  223.     }
  224.  }
  225.  
  226. function SetForcedEditorCharset(charset)
  227. {
  228.     if (charset.length > 0 ) {
  229.        gCharsetMenu.SetCurrentComposerCharset(charset);
  230.     }
  231.     EditorSetDocumentCharacterSet(charset);
  232. }
  233.  
  234.  
  235. var gLastMailCharset = null;
  236.  
  237. function mailCharsetLoadListener (event)
  238. {
  239.     if (msgWindow) {
  240.         var charset = msgWindow.mailCharacterSet;
  241.         if (charset.length > 0 && (charset != gLastMailCharset)) {
  242.             gCharsetMenu.SetCurrentMailCharset(charset);
  243.             gLastMailCharset = charset;
  244.         }
  245.     }
  246. }
  247.  
  248. var wintype = document.documentElement.getAttribute('windowtype');
  249. if (window && (wintype == "navigator:browser"))
  250. {
  251.     var contentArea = window.document.getElementById("appcontent");
  252.     if (contentArea)
  253.         contentArea.addEventListener("pageshow", charsetLoadListener, true);
  254. }
  255. else
  256. {
  257.     var arrayOfStrings = wintype.split(":");
  258.     if (window && arrayOfStrings[0] == "mail") 
  259.     {
  260.         var messageContent = window.document.getElementById("messagepane");
  261.         if (messageContent)
  262.             messageContent.addEventListener("pageshow", mailCharsetLoadListener, true);
  263.     }
  264.     else
  265.     if (window && arrayOfStrings[0] == "composer") 
  266.     {
  267.         contentArea = window.document.getElementById("appcontent");
  268.         if (contentArea)
  269.             contentArea.addEventListener("pageshow", composercharsetLoadListener, true);
  270.     }
  271.  
  272. }
  273.